<?php
//普通用户注册
include("../connectdb.php");
session_start();
if(isset($_POST['submit'])){
    $email = $_POST['email'];
    $username=$_POST['username'];
    $password=$_POST['password'];
    $sql = "SELECT email FROM normalUser WHERE email='".$email."'";
    $flag=mysqli_fetch_array(mysqli_query($conn,$sql));
    if($flag!=NULL){
        echo"<script>alert('邮箱已经被注册！');history.go(-1);</script>";
    }
    elseif($flag==NULL and $_POST['password']==$_POST['password2']){
            $sql="INSERT INTO normalUser (`id`,`username` ,`password`,`email`,`status`)values('','$username','$password','$email',1)";
            $result=mysqli_query($conn,$sql);
            echo "<script language=\"JavaScript\">alert('成功注册');location.href='login.php'</script>";
        }
    else{
          echo "<script language=\"JavaScript\">alert('信息有误！');history.go(-1)</script>";
    }
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Blogs 普通用户注册界面</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="../admin/assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="../admin/assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <link rel="stylesheet" href="../admin/assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="../admin/assets/css/amazeui.datatables.min.css" />
    <link rel="stylesheet" href="../admin/assets/css/app.css">
    <script src="../admin/assets/js/jquery.min.js"></script>
</head>

<body data-type="login">
    <script src="../admin/assets/js/theme.js"></script>
    <script language=JavaScript>
        function Checkpost(){
            if (form1.email.value==""){
                alert("邮箱不能为空");
                form1.email.focus();
                return false;
            }
            if(form1.username.value==""){
                alert("用户名不能为空");
                form1.username.focus();
                return false;
            }
            if(form1.password.value==""){
                alert("密码不能为空");
                form1.password.focus();
                return false;
            }
        }
    </script>
    <div class="am-g tpl-g">
        <!-- 风格切换 -->
        <div class="tpl-skiner">
            <div class="tpl-skiner-toggle am-icon-cog">
            </div>
            <div class="tpl-skiner-content">
                <div class="tpl-skiner-content-title">
                    选择主题
                </div>
                <div class="tpl-skiner-content-bar">
                    <span class="skiner-color skiner-white" data-color="theme-white"></span>
                    <span class="skiner-color skiner-black" data-color="theme-black"></span>
                </div>
            </div>
        </div>
        <div class="tpl-login">
            <div class="tpl-login-content">
                <div class="tpl-login-title">普通用户注册</div>
                <span class="tpl-login-content-info">
                  注册一个新的账户
              </span>


                <form class="am-form tpl-form-line-form" method="post" action="" name="form1" onsubmit="return Checkpost()">
                    <div class="am-form-group">
                        <input type="text" class="tpl-form-input" id="user-name" placeholder="邮箱" name="email">

                    </div>

                    <div class="am-form-group">
                        <input type="text" class="tpl-form-input" id="user-name" placeholder="用户名" name="username">
                    </div>

                    <div class="am-form-group">
                        <input type="password" class="tpl-form-input" id="user-name" placeholder="请输入密码" name="password">
                    </div>

                    <div class="am-form-group">
                        <input type="password" class="tpl-form-input" id="user-name" placeholder="再次输入密码" name="password2">
                    </div>

                    <div class="am-form-group">
                        <input type="submit" class="am-btn am-btn-primary  am-btn-block tpl-btn-bg-color-success  tpl-login-btn" name="submit" value="确认注册">

                    </div>
                </form>
            </div>
        </div>
    </div>
    <script src="../admin/assets/js/amazeui.min.js"></script>
    <script src="../admin/assets/js/app.js"></script>

</body>

</html>